package utils;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;

import java.io.IOException;

/**
 * Created by ZQ on 2016/4/23.
 * 从ui_main.png中截图
 */
public class Images {
    //传入大图片ui_main_png
    private static Bitmap uiMain;
    //传入顶部的图片
    private static Bitmap topImg;
    //截取顶部背景图片
    private static Bitmap topBackground;
    //截取已选定背景图片
    private static Bitmap selectBgImg;
    //截取未选定背景图片
    private static Bitmap bgImg;

    private static Bitmap backBtn;
    private static Bitmap coinImg;
    private static Bitmap leftDelete;
    private static Bitmap leftHint;
    private static Bitmap rightImg;
    private static Bitmap imgTitle;

    public static void init(Activity a) throws IOException {
        uiMain = BitmapFactory.decodeStream(a.getAssets().open("ui_main.png"));
        topImg = getImg(1020, 1939, 108, 108);
        topBackground = getImg(975, 893, 640, 96);
        selectBgImg = getImg(975, 338, 74, 76);
        bgImg = getImg(1602, 155, 66, 63);
        backBtn = getImg(98, 1972, 96, 72);
        coinImg = getImg(1602,219,44,33);
        leftDelete = getImg(1503, 990, 92, 123);
        leftHint = getImg(1579, 1371, 92, 123);
        rightImg = getImg(1305, 1865, 95, 95);
        imgTitle = getImg(1675, 787, 310, 58);
    }

    //切图
    public static Bitmap getImg(int x, int y, int width, int height) {
        //根据坐标位置截取ui.main.png固定位置的图形
        return Bitmap.createBitmap(uiMain, x, y, width, height);
    }

    //adroid手机特性：可以对图像进行缩放
    public static Bitmap changeImgSize(Bitmap source, int sizeX, int sizeY) {
        Matrix mat = new Matrix();
        mat.postScale(sizeX/source.getWidth(), sizeY/source.getHeight());
        return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), mat, false);
    }

    //图形旋转操作
    public static Bitmap rotateImg(Bitmap source) {
        Matrix mat = new Matrix();
        mat.postRotate(25, source.getWidth()/2, source.getHeight()/2);
        return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), mat, false);
    }

    public static Bitmap getTopImg() {
        return topImg;
    }

    public static Bitmap getTopBackground() {
        return topBackground;
    }

    public static Bitmap getSelectBgImg() {
        return selectBgImg;
    }

    public static Bitmap getBgImg() {
        return bgImg;
    }

    public static Bitmap getBackBtn() {
        return backBtn;
    }

    public static Bitmap getCoinImg() {
        return coinImg;
    }

    public static Bitmap getLeftDelete() {
        return leftDelete;
    }

    public static Bitmap getLeftHint() {
        return leftHint;
    }

    public static Bitmap getRightImg() {
        return rightImg;
    }

    public static Bitmap getImgTitle() {
        return imgTitle;
    }

}
